const {resolve} = require("path");
const osType = require('os').type();
const openAppName =
	osType === "Darwin" ? "Google Chrome" :
		osType === "Linux" ? "google-chrome" : "chrome";
const htmlWebpackPlugin = require("html-webpack-plugin");
const {CleanWebpackPlugin} = require('clean-webpack-plugin');
module.exports = {
	entry: "./src/index.js",
	output: {
		filename: "[contenthash:10].js",
		path: resolve(__dirname, "dist"),
		// library: "jsModule",
		// libraryTarget: "umd"
	},
	module: {
		rules: [
			{
				test: /\.js/,
				exclude: /node_modules/,
				use: {
					loader: "babel-loader",
					options: {
						presets: [
							[
								'@babel/preset-env',
								{
									targets: {
										chrome: "70",
										firefox: "60",
										ie: "9"
									}
								}
							]
						]
					}
				}
			}
		]
	},
	plugins: [
		new htmlWebpackPlugin({
			template: "./public/index.html",
			minify: {
				removeAttributeQuotes: true,
				removeComments: true,
				collapseWhitespace: true
			}
		}),
		new CleanWebpackPlugin()
	],
	mode: "development",
	devServer: {
		compress: true,
		port: 3500,
		open: {
			app: {
				//浏览器应用程序名称与平台相关。不要在可重用模块中硬编码它。例如，'Chrome' 在 macOS 是 'Google Chrome'，在 Linux 是 'google-chrome'，在 Windows 是 'chrome'。
				name: openAppName,
			},
		},
		hot: true,
		client: {
			progress: true,
		},
	}
}
